1 module unde.games.dizzy.omega.animations.fall_platform; 2 3 import derelict.opengl3.gl; 4 import std.conv; 5 import std.format; 6 import std.math; 7 import unde.games.dizzy.omega.dizzy; 8 import unde.games.object; 9 import unde.games.renderer; 10 import unde.global_state; 11 12 class FallPlatform:StaticGameObject 13 { 14 static int num; 15 int number; 16 Dizzy the_hero; 17 18 this(MainGameObject root, Dizzy hero, float[3] coords, int number) 19 { 20 frame = -1; 21 x = coords[0]; 22 y = coords[1]; 23 z = coords[2]; 24 number = num++; 25 models["fall-platform"] = root.models[format("fall-platform-%d", number)]; 26 the_hero = hero; 27 super(root); 28 } 29 30 override void draw(GlobalState gs) 31 { 32 glPushMatrix(); 33 if (frame < 0) 34 { 35 glTranslatef(x, y, z); 36 recursive_render(gs, models["fall-platform"]); 37 } 38 else 39 { 40 float f = root.frame - frame; 41 if (f < 100.0) 42 { 43 glTranslatef(x, y - 20.0*f/100.0, z); 44 recursive_render(gs, models["fall-platform"]); 45 } 46 } 47 glPopMatrix(); 48 } 49 50 override bool tick(GlobalState gs) 51 { 52 if (frame < 0 && abs(x-the_hero.x) < the_hero.bottom_sensor_dx && abs(y-the_hero.y) < 0.2) 53 { 54 frame = root.frame; 55 } 56 57 return true; 58 } 59 60 override void load(string[string] s) 61 { 62 string p = "fall-platform-"~number.to!(string); 63 if (p in s) 64 frame = s[p].to!(long); 65 else 66 frame = -1; 67 } 68 69 override void save(ref string[string] s) 70 { 71 if (frame >= 0) 72 { 73 string p = "fall-platform-"~number.to!(string); 74 s[p] = frame.to!(string); 75 } 76 } 77 }